<?php namespace Admin\Controller;
use Common\Model\Type;

class TypeController extends CommonController{
    private $model;
    public function __auto(){
        $this->model=new Type();
    }
//    显示所有类型
    public function index(){
//        获取表中数据
        $tdata=$this->model->get();
//        p($tdata);
        View::with('tdata',$tdata);
        View::make();
    }
//    添加类型
    public function addType(){
        if(IS_POST){
            if($this->model->store()){
                View::success('添加成功',U('index'));
            }else{
                View::error($this->model->getError());
            }
        }
        View::make();
    }

//    类型的删除
    public function delType(){
        $tid=Q('get.tid',0,'intval');
        $this->model->where("tid={$tid}")->delete();
        View::success('删除成功');
    }


//    类型的编辑
    public function editType(){
        if(IS_POST){
            if($this->model->edit()){
                View::success('编辑成功',U('index'));
            }else{
                View::error($this->model->getError());
            }
        }

        $tid=Q('get.tid',0,'intval');
        $tname=$this->model->where("tid={$tid}")->pluck('tname');
        View::with('tname',$tname);
        View::make();
    }

//    显示属性类型
    public function typeid(){
        $tid=Q('get.tid',0,'intval');
        $_SESSION['info']['tid']=$tid;
        go(U('Attlist/index'));
    }
}